* THIS FILE GENERATES FIGURES 5 AND 6
* FIRST, AGGREGATED RESULTS ARE GENERATED
* THEN, AGGREGATED RESULTS ARE TRANSFERRED TO EXCEL
* THE AGGREGATED RESULTS ARE THEN READ TO CREATE THE FIGURES


* GENERATE AGGREGATED RESULTS FOR PUBLIC SAMPLE

set more off
clear

* SET DIRECTORY HERE 
cd "C:\Users\mitch\Dropbox\BLW\POP\Searching for a Bright Line\Searching for a Bright Line replication materials" 

log using "Logs/BLW-figures 5,6.log", replace text

use "Data/BLW_Public_Waves3456.dta", clear


recode imp_misconduct-imp_investigations (0=0) (1=0) (2=1) (3=1) 
recode perf_misconduct-perf_investigations (1=0) (2=0) (3=1) (4=1) (5=.)

tabstat imp_misconduct-imp_investigations if (wave==3) [aw=weight], format(%8.4f) col(statistics) la(25) var(25)
tabstat perf_misconduct-perf_investigations if (wave==6) [aw=weight], format(%8.4f) col(statistics) la(25) var(25)



* GENERATE AGGREGATED RESULTS FOR EXPERT SAMPLE

clear
use "Data/BLW_Expert_Waves123456.dta", clear

recode imp_misconduct-imp_investigations (0=0) (1=0) (2=1) (3=1)
label value imp_misconduct-imp_investigations statementlabel  

recode perf_misconduct-perf_investigations (1=0) (2=0) (3=1) (4=1) (5=.)
label value perf_misconduct-perf_investigations statementlabel

tabstat imp_misconduct-imp_investigations if (wave==3), format(%8.4f) col(statistics) var(25)
tabstat perf_misconduct-perf_investigations if (wave==6), format(%8.4f) col(statistics) var(25)




* RESULTS ABOVE ARE COPIED AND PASTED IN TO EXCEL (OUTSIDE THE SCOPE OF THIS .DO FILE, THEN THE SYNTAX BELOW GENERATES THE FIGURES
* BOTH FIGURES ARE ORDERED BASED ON EXPERT IMPORTANCE


clear
import excel "Data/figures 5 and 6.xlsx", sheet("results") firstrow clear


twoway scatter Perf6_Experts Imp3_Experts , graphregion(color(white)) mlabel (Order_Experts_Importance) ///
xlabel(0.4  "40%"  0.5  "50%"  0.6  "60%"  0.7  "70%"  0.8  "80%"  0.9  "90%"  1.0  "100%", labsize(3.75) noticks grid gmin gmax)  ///
ylabel(0  "0%"  0.1  "10%"  0.2  "20%"  0.3  "30%"  0.4  "40%"  0.5  "50%"  0.6  "60%"  0.7  "70%"  0.8  "80%"  0.9  "90%"  1  "100%", labsize(3.75) noticks grid gmin gmax) ///
mlabposition (0)  msymbol(i)  mlabcolor(green)  mlabsize(4)  ylabel(, angle(horizontal)) ///
xtitle(" " `"Percentage who answered statement is "important""' `"or "essential" for democratic government (Sept. 2017)"') ///
ytitle(" " `"Percentage who answered U.S. "fully""'  `"or "mostly meets" standard (July 2018)"')  

graph export "Figures/Figure 5a (Experts).png", width(2000) replace
* graph export "Figures/Figure 5a (Experts).tif", width(10000) replace


twoway scatter Perf6_Public Imp3_Public , graphregion(color(white)) mlabel (Order_Experts_Importance) ///
xlabel(0.4  "40%"  0.5  "50%"  0.6  "60%"  0.7  "70%"  0.8  "80%"  0.9  "90%"  1.0  "100%", labsize(3.75) noticks grid gmin gmax)  ///
ylabel(0  "0%"  0.1  "10%"  0.2  "20%"  0.3  "30%"  0.4  "40%"  0.5  "50%"  0.6  "60%"  0.7  "70%"  0.8  "80%"  0.9  "90%"  1  "100%", labsize(3.75) noticks grid gmin gmax) ///
mlabposition (0)  msymbol(i)  mlabcolor(purple)  mlabsize(4)  ylabel(, angle(horizontal)) ///
xtitle(" " `"Percentage who answered statement is "important""' `"or "essential" for democratic government (Sept. 2017)"') ///
ytitle(" " `"Percentage who answered U.S. "fully""'  `"or "mostly meets" standard (July 2018)"')  

graph export "Figures/Figure 6a (Public).png", width(2000) replace
* graph export "Figures/Figure 6a (Public).tif", width(10000) replace


log close




